﻿using System;
using System.Web.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using LOMBARDISPICK.Model;
using LOMBARDISPICK.Model.Repositories;
using LOMBARDISPICK.Model.Infrastructure;
using LOMBARDISPICK.Domain.Infrastructure;

namespace LOMBARDISPICK.Domain.Services
{
	public class TeamSeason_1985_2011Service : ServiceBase<TeamSeason_1985_2011, ITeamSeason_1985_2011Repository>, ITeamSeason_1985_2011Service
	{
		public TeamSeason_1985_2011Service(ITeamSeason_1985_2011Repository repository, IUnitOfWork unitOfWork)
			: base(unitOfWork, repository)
		{
		}

		/// <summary>
		///	Get a sorted IEnumerable.
		/// </summary>
		public override IEnumerable<TeamSeason_1985_2011> getAllSorted()
		{
			return this.getAll().OrderBy(this.orderExpression()).ThenBy(this.orderExpression2());
		}

		/// <summary>
		///	Get a sorted IEnumerable with where parameters.
		/// </summary>
		public override IEnumerable<TeamSeason_1985_2011> getManySorted(Expression<Func<TeamSeason_1985_2011, bool>> where)
		{
			return this.getMany(where).OrderBy(this.orderExpression()).ThenBy(this.orderExpression2());
		}

		/// <summary>
		///	Retrieve a select list
		/// </summary>
		public override IEnumerable<SelectListItem> getSelectList()
		{
			var SelectOptions =
				this.getAllSorted().Select(StandardSelectListOptionsExpression(false));
			return SelectOptions;
		}

		/// <summary>
		///	Retrieve a select list with where filter
		/// </summary>
		public IEnumerable<SelectListItem> getSelectList(Expression<Func<TeamSeason_1985_2011, bool>> whereFilter)
		{
			var selectOptions =
			this.getManySorted(whereFilter).Select(
				StandardSelectListOptionsExpression(false));
			return selectOptions;
		}

		/// <summary>
		///	Retreive all valid entities in the form of a select list.
		/// </summary>
		public override SelectList ViewDataSelectLists()
		{
			return new SelectList(this.getSelectList(), "Value", "Text");
		}

		/// <summary>
		///	Retreive all valid entities in the form of a select list with a default starting/selected value.
		/// </summary>
		public override SelectList ViewDataSelectListsWithDefaultValue(int id)
		{
			return new SelectList(this.getSelectList(), "Value", "Text", this.getById(id).TeamSeasonID);
		}

		/// <summary>
		///	Retreive all valid entities in the form of a select list. Using an expression
		/// </summary>
		public override SelectList ViewDataSelectLists(Expression<Func<TeamSeason_1985_2011, bool>> where)
		{
			return new SelectList(this.getSelectList(where), "Value", "Text");
		}

		/// <summary>
		///	Retreive all valid entities in the form of a select list with a default starting/selected value. Using an expression
		/// </summary>
		public override SelectList ViewDataSelectListsWithDefaultValue(Expression<Func<TeamSeason_1985_2011, bool>> where, int id)
		{
			return new SelectList(this.getSelectList(where), "Value", "Text", this.getById(id).TeamSeasonID);
		}

		/// <summary>
		///	Retreive default value from this entity in the form of a string.
		/// </summary>
		public override string ViewDataDefaultValue(int id)
		{
			return this.getById(id).Season.ToString() + " - " + this.getById(id).NFLTeam.TeamNameAbbreviations;
		}

		/// <summary>
		///	Standard SelectList Lambda expression for this entity.
		/// </summary>
		public override Func<TeamSeason_1985_2011, SelectListItem> StandardSelectListOptionsExpression(bool IsSelected)
		{
			return u =>
					new SelectListItem
					{
						Selected = IsSelected,
						Value = u.TeamSeasonID.ToString(),
						Text = u.Season.ToString() + " - " + u.NFLTeam.TeamNameAbbreviations
					};
		}

		/// <summary>
		///	Orderby Lambda expression for this entity.
		/// </summary>		
		private Func<TeamSeason_1985_2011, int> orderExpression()
		{
			return x => x.Season;
		}

		/// <summary>
		///	Orderby Lambda expression for this entity.
		/// </summary>		
		private Func<TeamSeason_1985_2011, string> orderExpression2()
		{
			return x => x.NFLTeam.TeamNameAbbreviations;
		}
	}

	public interface ITeamSeason_1985_2011Service : IService<TeamSeason_1985_2011>
	{
	}
}
